package cn.itcast.sailing.util; // 这里的包名根据您的项目结构而定


import java.io.Serializable;
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L; // 序列化ID，用于反序列化时保持类的一致性

    // 定义通用的状态码，可根据实际项目需求定义
    public static final int SUCCESS_CODE = 0;
    public static final int FAILURE_CODE = -1;

    private int code;
    private String message;
    private T data;

    // 默认构造器
    public Result() {}

    // 参数化的构造器
    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 泛型数据的getter和setter
    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 状态码和消息的getter和setter
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    // 静态工厂方法
    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, "success", data);
    }

    public static <T> Result<T> failure(String message) {
        return new Result<>(FAILURE_CODE, message, null);
    }

    public static <T> Result<T> failure(int code, String message) {
        return new Result<>(code, message, null);
    }
}